#!/usr/bin/perl

$prevDown = 0;
$prevUp   = 0;

while (1) {
    $output = `/sbin/ifconfig eth0`;
    if ($output =~ /RX\s+bytes:(\d+).+TX\s+bytes:(\d+)/) {
        if ($prevDown != 0) {
            $down = $1 - $prevDown;
            $up   = $2 - $prevUp;

            printf("down %4.2f\tup %4.2f\n",
                   $down / 1024.0, $up / 1024.0);
        }

        $prevDown = $1;
        $prevUp   = $2;
    }
    else {
        printf("invalid ifconfig output !!!\n");
    }

    sleep(1);
}
